<template>
  <div class="qingwu">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <!-- class="admin_main_block_left" -->
        <div>
          <div>
            <el-form ref="form" :inline="true" :model="where" label-width="100px">
              <el-row>
                <el-col :span="8">
                  <el-form-item label="商品名称">
                    <el-input v-model="where.goods_name" clearable />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="品牌">
                    <el-select v-model="where.bid" clearable placeholder="请选择">
                      <el-option
                        v-for="item in brandList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="分类">
                    <el-select v-model="where.cid" clearable placeholder="请选择">
                      <el-option
                        v-for="item in cidList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <!-- <el-col :span="8">
                <el-form-item label="关键词">
                  <el-input v-model="where.keyword" clearable />
                </el-form-item>
                </el-col>-->
                <el-col :span="8">
                  <el-form-item label="上架状态">
                    <el-select v-model="where.goods_status" clearable placeholder="请选择">
                      <el-option
                        v-for="item in isOnList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6" :offset="2">
                  <el-form-item>
                    <!-- <router-link to="/Seller/goods/chose_class">
                      <el-button type="primary" icon="el-icon-plus">添加</el-button>
                    </router-link>-->
                    <el-button
                      icon="el-icon-search"
                      type="primary"
                      class="mr"
                      @click="get_goods_list()"
                    >查询</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
          <!-- <div>
            <router-link to="/Admin/goods/goods_verify">
              <el-badge
                v-if="goods_verify_count>0"
                :value="goods_verify_count"
                :max="99"
                class="item"
              >
                <el-button icon="el-icon-receiving">待审核列表</el-button>
              </el-badge>
              <el-button v-else icon="el-icon-receiving">待审核列表</el-button>
            </router-link>
          </div>-->
          <!-- <div><el-input v-model="name" placeholder="请输入内容"></el-input></div>
          <div><el-button icon="el-icon-search">条件筛选</el-button></div>-->
          <!-- <div>
            <el-input v-model="where.goods_name" placeholder="商品名"></el-input>
          </div>
          <div style="width:160px;">
            <el-select v-model="where.type" placeholder="选择类型">
              <el-option label="全部" value></el-option>
            </el-select>
          </div>
          <div>
            <el-button icon="el-icon-search" @click="get_goods_list()">条件筛选</el-button>
          </div>-->
        </div>

        <!-- <div class="admin_main_block_right">
          <div><el-button type="danger" icon="el-icon-delete" @click="del(select_id)">批量删除</el-button></div>
        </div>-->
      </div>
      <div class="admin_table_main">
        <el-table :data="list" @selection-change="handleSelectionChange">
          <!-- <el-table-column type="selection"></el-table-column> -->
          <!-- <el-table-column prop="id" label="#" fixed="left" width="70px"></el-table-column> -->
          <el-table-column :index="table_index" fixed type="index" label="序号" width="70px"></el-table-column>
          <el-table-column label="商品名称" width="150px" prop="goods_name"></el-table-column>
          <el-table-column prop="brand_cn" label="品牌" />
          <el-table-column prop="class_name_cn" label="分类" />
          <el-table-column prop="goods_user_price" label="会员价" />
          <!-- <el-table-column prop="goods_price" label="非会员价" /> -->
          <el-table-column prop="spec_cn" label="规格" />
          <el-table-column prop="keyword_name_cn" label="关键词" />
          <el-table-column prop="goods_sale_num_virtual" label="虚拟销量" />
          <el-table-column prop="goods_sale_num" label="实际销量" />
          <el-table-column prop="goods_freight" label="运费" />
          <el-table-column prop="add_time" label="创建时间" />
          <el-table-column label="推荐首页" width="100px">
            <template slot-scope="scope">
              <div
                :class="scope.row.is_index==1?'green_round':'gray_round'"
                @click="goods_index(scope.row.id)"
              ></div>
            </template>
          </el-table-column>
          <!-- <el-table-column label="商品状态">
                        <template slot-scope="scope">
                            <el-tag type="success" v-if="scope.row.goods_verify==1">通过</el-tag>
                            <el-tag type="warning" v-else-if="scope.row.goods_verify==2">审核中</el-tag>
                            <el-tag type="danger" v-else-if="scope.row.goods_verify==0">失败</el-tag>
                        </template> 
          </el-table-column>-->
          <el-table-column label="是否上架">
            <template slot-scope="scope">
              <div
                :class="scope.row.goods_status==1?'green_round':'gray_round'"
                @click="goods_status(scope.row.id)"
              ></div>
            </template>
          </el-table-column>

          <!-- <el-table-column prop="goods_price" label="价格"></el-table-column>
                    <el-table-column prop="all_goods_num" label="库存">
                        <template slot-scope="scope">
                            <div>{{scope.row.all_goods_num||scope.row.goods_num}}</div>
                        </template> 
                    </el-table-column>
                    <el-table-column label="修改时间">
                        <template slot-scope="scope">
                            <div>{{scope.row.edit_time|formatDate}}</div>
                        </template> 
          </el-table-column>-->
          <el-table-column label="操作" fixed="right" width="120px">
            <template slot-scope="scope">
              <el-button
                icon="el-icon-edit"
                :disabled="scope.row.goods_verify==1 || scope.row.goods_verify==0"
                @click="verify_click(scope.row.id)"
              >审核</el-button>
              <!-- <el-button type="danger" icon="el-icon-delete" @click="del(scope.row.id)">删除</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <div class="admin_table_main_pagination">
          <el-pagination
            @current-change="current_change"
            background
            layout="prev, pager, next,jumper,total"
            :total="total_data"
            :page-size="where.page_size"
            :current-page="current_page"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      list: [],
      total_data: 0, // 总条数
      current_page: 1,
      select_id: "",
      goods_verify_count: 0,
      where: {
        bid: "",
        cid: "",
        goods_name: "",
        goods_status: "",
        page: "",
        page_size: 20,
        goods_name: "",
      },
      brandList: [], //品牌
      isOnList: [], // 上架状态
      cidList: [], //分类列表
    };
  },
  watch: {},
  computed: {},
  mounted() {
    this.getSelectlist();
  },

  methods: {
    //   序号
    table_index(index) {
      return (this.where.page - 1) * this.where.page_size + index + 1;
    },
    // 获取下拉数据
    getSelectlist() {
      this.$get(this.$api.getSearchSelect).then((res) => {
        console.log("res", res);
        if (res.code == 200) {
          this.isOnList = res.data.on_shelf_list;
          this.cidList = res.data.goods_class_list;
          this.brandList = res.data.goods_brand_list;
        }
      });
    },
    handleSelectionChange: function (e) {
      let ids = [];
      e.forEach((v) => {
        ids.push(v.id);
      });
      this.select_id = ids.join(",");
    },
    get_goods_list: function () {
      this.where.page = this.current_page;
      this.$post(this.$api.getAdminGoodsList, this.where).then((res) => {
        this.where.page_size = res.data.per_page;
        this.total_data = res.data.total;
        this.current_page = res.data.current_page;
        this.list = this.$formatGoods(res.data.data);
        this.goods_verify();
      });
    },
    // 删除处理
    del: function (id) {
      if (this.$isEmpty(id)) {
        return this.$message.error("请先选择删除的对象");
      }
      this.$post(this.$api.delGoods, { id: id }).then((res) => {
        if (res.code == 200) {
          this.get_goods_list();
          return this.$message.success("删除成功");
        } else {
          return this.$message.error("删除失败");
        }
      });
    },
    // 指定ID修改状态
    goods_status: function (id) {
      this.$post(this.$api.adminGoodsStatus, { id: id }).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功");
        } else {
          this.$message.success("操作失败");
        }
        this.get_goods_list();
      });
    },
    goods_index: function (id) {
      this.$post(this.$api.adminGoodsIndex, { id: id }).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功");
        } else {
          this.$message.success("操作失败");
        }
        this.get_goods_list();
      });
    },
    // 获取待审核数据
    goods_verify: function () {
      this.$post(this.$api.goodsVerify, { page: this.current_page }).then(
        (res) => {
          this.goods_verify_count = res.data.total;
        }
      );
    },
    verify_click: function (id) {
      this.$confirm("此操作将控制商品是否通过审核, 是否继续?", "提示", {
        confirmButtonText: "同意",
        cancelButtonText: "拒绝",
        type: "info",
      })
        .then(() => {
          this.$post(this.$api.goodsVerifyChange, { id: id, status: 1 }).then(
            () => {
              this.$message.success("成功审核");
              this.get_goods_list();
            }
          );
        })
        .catch(() => {
          this.$post(this.$api.goodsVerifyChange, { id: id, status: 0 }).then(
            () => {
              this.$message.info("已拒绝");
              this.get_goods_list();
            }
          );
        });
    },
    current_change: function (e) {
      this.current_page = e;
      this.get_goods_list();
    },
  },
  created() {
    this.get_goods_list();
  },
};
</script>
<style lang="scss" scoped>
</style>